﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using Db8.Data;

namespace Db8.DataAccess
{
    public partial class Db8Context : DbContext
    {
        public DbSet<ClaimKeyword> ClaimKeywords { get; set; }
        public DbSet<Claim> Claims { get; set; }
        public DbSet<CounterClaim> CounterClaims { get; set; }
        public DbSet<Keyword> Keywords { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<SupportingClaim> SupportingClaims { get; set; }
        //public DbSet<UserActivity> UserActivities { get; set; }
        public DbSet<UserRole> UserRoles { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Log> Log { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<CounterClaim>()
                .HasRequired(cc => cc.TargetClaim)
                .WithMany(c => c.CounterClaims)
                .HasForeignKey(cc => cc.TargetClaimId)
                .WillCascadeOnDelete(false);
            modelBuilder.Entity<CounterClaim>()
                .HasRequired(cc => cc.Claim)
                .WithMany(c => c.CounteredClaims)
                .HasForeignKey(cc => cc.ClaimId)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<SupportingClaim>()
                .HasRequired(sc => sc.TargetClaim)
                .WithMany(c => c.SupportingClaims)
                .HasForeignKey(sc => sc.TargetClaimId)
                .WillCascadeOnDelete(false);
            modelBuilder.Entity<SupportingClaim>()
                .HasRequired(sc => sc.Claim)
                .WithMany(c => c.SupportedClaims)
                .HasForeignKey(sc => sc.ClaimId)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<UserRole>()
                .HasRequired(ur => ur.User)
                .WithMany(u => u.UserRoles)
                .HasForeignKey(ur => ur.UserId)
                .WillCascadeOnDelete(false);
            modelBuilder.Entity<UserRole>()
                .HasRequired(ur => ur.Role)
                .WithMany(r => r.RoleUsers)
                .HasForeignKey(ur => ur.RoleId)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Claim>()
                .HasRequired(c => c.CreatedByUser)
                .WithMany(u => u.CreatedClaims)
                .HasForeignKey(c => c.CreatedBy)
                .WillCascadeOnDelete(false);
            modelBuilder.Entity<Claim>()
                .HasRequired(c => c.ModifiedByUser)
                .WithMany(u => u.LastModifiedClaims)
                .HasForeignKey(c => c.ModifiedBy)
                .WillCascadeOnDelete(false);

            //modelBuilder.Entity<UserActivity>()
            //    .HasRequired(c => c.User)
            //    .WithMany(u => u.UserActivities)
            //    .HasForeignKey(c => c.UserId)
            //    .WillCascadeOnDelete(false);

            base.OnModelCreating(modelBuilder);
        }





    }
}
